#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
struct ListNode
{
    int val;
    struct ListNode* next;
};
int* printListFromTailToHead(struct ListNode* phead, int* returnSize)
{
    // write code here
    int count = 0;
    struct ListNode* tmp = phead;
    while (tmp)
    {
        tmp = tmp->next;
        count++;
    }
    if (count == 0)
        return NULL;

    tmp = phead;

    int* arr = (int*)malloc(sizeof(int) * count);
    for (int i = count - 1; i >= 0; i--)
    {
        arr[i] = tmp->val;
        tmp = tmp->next;
    }
    *returnSize = count;
    return arr;
}